package com.wuseguang.springcloud.controller;


import com.wuseguang.springcloud.Filter.RequestParameterWrapper;
import com.wuseguang.springcloud.entity.ClassGroup;
import com.wuseguang.springcloud.service.GroupService;
import com.wuseguang.springcloud.util.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 小组表 前端控制器
 * </p>
 *
 * @author 
 * @since 2020-02-07
 */
@RestController
@RequestMapping("/group")
public class GroupController {


    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private GroupService groupServiceImpl;


    /**
     * 班级班级的小组信息
     * @param request
     * @param classId 班级id
     * @return
     */
    @RequestMapping(value = "/findClassIdGroup")
    public Result findClassIdGroup(RequestParameterWrapper request,
                                   @RequestParam(value = "classId",required = false)Integer classId){

        logger.info("查询班级的小组信息");
        //教师id
        String teacherId = request.getParam("teacherId");
        //学期id
        String termId = request.getParam("termId");

        return groupServiceImpl.findClassIdGroup(classId,teacherId,termId);
    }

    /**
     * 添加班级小组
     * @param request
     * @param classGroup
     * @return
     */
    @RequestMapping(value = "/addClassIdGroup")
    public Result addClassIdGroup(RequestParameterWrapper request,@RequestBody ClassGroup classGroup){
        logger.info("添加班级小组");
        //教师id
        String teacherId = request.getParam("teacherId");
        classGroup.setTeacherId(Integer.valueOf(teacherId));
        return groupServiceImpl.addClassIdGroup(classGroup);
    }


    /**
     * 解散小组
     * @param request
     * @param id 小组id
     * @return
     */
    @RequestMapping(value = "/deleteClassGroup")
    public  Result deleteClassGroup(RequestParameterWrapper request,
                                    @RequestParam(value = "id")Integer id){
        logger.info("解散小组");
        return groupServiceImpl.deleteClassGroup(id);
    }

    /**
     * \
     * @param request
     * @param classGroup
     * @return
     */
    @RequestMapping(value = "/updateClassGroup")
    public Result updateClassGroup(RequestParameterWrapper request,@RequestBody ClassGroup classGroup){
        logger.info("修改小组成员");
        return groupServiceImpl.updateClassGroup(classGroup);
    }
}

